package com.atsongyr.springcloud.controller;

import com.atsongyr.springCloud.entity.CommonResult;
import com.atsongyr.springCloud.entity.Payment;
import com.atsongyr.springcloud.service.PaymentFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author songyurui
 */
@RestController
@Slf4j
public class OrderFeignController {

    @Resource
    private PaymentFeignService paymentFeignService;

    @GetMapping("/consumer/feign/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id){
        // 如此一来，可以调用到8001的服务
        return paymentFeignService.getPaymentById(id);
    }

    /**
     * 测试超时地址
     * @return
     */
    @GetMapping(value = "/consumer/payment/feign/timeout")
    public String paymentFeignTimeOut(){
        // OpenFeign 底层是ribbon，客户端（消费者）一般默认等待一秒钟。
        return paymentFeignService.paymentFeignTimeOut();
    }
}
